const http = require('http')

// http.createServer((request, response) => {
//   let body = []
//   request.on('error', err => {
//     console.error(err)
//   }).on('data', chunk => {
//     body.push(chunk)
//   }).on('end', () => {
//     // body = Buffer.concat(body).toString()
//     body = body.join('')
//     console.log('body', body)
//     response.writeHead(200, {'Content-Type': 'text/html'})
//     response.end(' Hello World\n')
//   })
// }).listen(8088)

// console.log('sever start')

const server = http.createServer((req, res) => {
  console.log('request received')
  console.log(req.headers)
  res.setHeader('Content-Type', 'text/html')
  res.setHeader('X-Foo', 'bar')
  res.writeHead(200, { 'Content-Type': 'text/plain' })
  res.end(
`<html lang=en>
<head>
  <style>
body div #myid{
  width: 100px;
  background-color: #000000;
}
body div img{
  width: 30px;
  background-color: #ff1111;
}
  </style>
</head>
<body>
  <div>
    <img id="myid" />
    <img />
  </div>
</body>
</html>`
  )
})

server.listen(8088)
